#pragma once

namespace	MomogenkyouHelper	{

class Sprite
{
protected:
	MomogenkyouSystem::TextureData	*	m_pTextureData;	//	The texture attached to this sprite
	MomogenkyouSystem::Vertex			m_Vertices[4];	//	Vertices for rendering Quad
	

	float2	m_vTxSize;									//	Texture Coordinate Size (0 ~ 1)
	float2	m_vTxPosition;								//	Texture Coordinate Position (0 ~ 1)

	float2	m_vWidthHeight;								//	Width and Height of the quad

	bool	m_bXFlip, m_bYFlip;							//	Fliping of image
	bool	m_bXZ;										//	If quad is XY or XZ based, default is XY

	void		PrepareVertices();
public:
	//	@param	pTexture		The texture to attach to this sprite
	//	@param	vTxPosition		TexCoord of start point (0 ~ 1)
	//	@param	vTxSize			Size from the TexCoord start point (0 ~ 1)
	//	@param	vWidthHeight	Width and Height of this quad.
	//	@param	bXZ				Flag to indicate if the quad is Facing Upwards
	Sprite(MomogenkyouSystem::TextureData * pTexture,	
			const	float2	&	vTxPosition, 
			const	float2	&	TxSize, 
			const	float2	&	vWidthHeight,
					bool		bXZ = false);

	//	@param	pTexture		The texture to attach to this sprite
	//	@param	fTx		fTy		TexCoord of start point (0 ~ 1)
	//	@param	fTsx	fTsy	Size from the TexCoord start point (0 ~ 1)
	//	@param	fWidth fHeight	Width and Height of this quad.
	//	@param	bXZ				Flag to indicate if the quad is Facing Upwards
	Sprite(MomogenkyouSystem::TextureData * pTexture,	
			const	float	&	fTx,		const	float	&	fTy, 
			const	float	&	fTsx,		const	float	&	fTsy,
			const	float	&	fWidth,		const	float	&	fHeight,
													bool		bXZ = false);
	virtual	~Sprite();

	//	Retrieve the vertex data of this sprite
	__inline	MomogenkyouSystem::Vertex		*	Vertices()		{	return	m_Vertices;				}
	
	//	Retrieve the texture data of this sprite
	__inline	MomogenkyouSystem::TextureData	*	TextureData()	{	return	m_pTextureData;			}

	//	TexCoord of Reference point (0 ~ 1)
	__inline	float2	TxPosition()	const						{	return	m_vTxPosition;			}
	
	//	TexCoord of Width and Height (0 ~ 1)
	__inline	float2	TxWidthHeight()	const						{	return	m_vTxSize;				}
	
	//	Width and Height of the Quad
	__inline	float2	WidthHeight()	const						{	return	m_vWidthHeight;			}
	
	//	Change the Width and Height of the quad
	//	@param vWidthHeight	Size of the quad, unit of measurement varies
	__inline	float2	WidthHeight(const float2 & vWidthHeight)	{	m_vWidthHeight = vWidthHeight;	}

	//	Color of the Sprite
	__inline	float4	Color()			const						{	return	m_Vertices[0].Color;	}

	//	Apply Color change to all vertex
	//	@param	vColor	RGBA
	__inline	void	Color(const float4 & vColor)				{	
																		m_Vertices[0].Color = vColor; m_Vertices[1].Color = vColor; 
																		m_Vertices[2].Color = vColor; m_Vertices[3].Color = vColor;		
																	}
	//	Retrieve the Depth / Z value from the First / Reference Vertex.
	__inline	float	Depth()			const						{	return	m_Vertices[0].Position.z;	}

	//	Change the attached Texture data
	//	@param	pTexture	Target texture to use
	void		SetTexture(MomogenkyouSystem::TextureData	* pTexture);

	//	Change the TexCoords according to parameters
	//	@param	fx  fy	TexCoord's UV
	//	@param	fw	fh	Width and Height in UV values (0 ~ 1)

	void		SetTextureRect(const float & fx, const float & fy, const float & fw, const float & fh);
	
	//	Flip the image either Horizontal or Vertical
	//	@param	bX	Flag to flip Vertical
	//	@param	bY	Flag to flip Horizontal
	void		SetFlip(bool bX, bool bY);
};

}